package 力扣._00周赛._145双周赛.问题2;

import java.util.ArrayList;
import java.util.List;

class Solution {
    int time = Integer.MAX_VALUE;
    void backtrace(List<Integer> strength,int x, int k,int[] visited,List<Integer> nowList){
        if(nowList.size()==strength.size()){
            int sum = 0;
            for (int i : nowList) {
                sum += (int)(Math.ceil(i*1.0 / x));
                x += k;
            }
            time = Math.min(time, sum);
            return;
        }
        for (int i = 0; i < strength.size(); i++) {
            if(visited[i]==0){
                visited[i] = 1;
                nowList.add(strength.get(i));
                backtrace(strength,x, k, visited, nowList);
                nowList.remove(nowList.size()-1);
                visited[i] = 0;
            }
        }

    }

    public int findMinimumTime(List<Integer> strength, int K) {
        // 开锁顺序问题，最多10把锁，直接回溯
        int[] visited = new int[strength.size()];
        backtrace(strength,1, K, visited, new ArrayList<>());
        return time;
    }

    public static void main(String[] args) {
        // [3,4,1]
        //1
        List<Integer> list = new ArrayList<>();
        list.add(3);
        list.add(4);
        list.add(1);
        System.out.println(new Solution().findMinimumTime(list, 1));

    }
}